<?php

require __DIR__.'/vendor/autoload.php';

use Yaroslam\SSH2\Session\Connection\UserPasswordConnection;

$a = [
    [
        'type' => 'if',
        'command' => 'ls -la',
        'condition' => '.ssh',
        'then' => [
            ['type' => 'exec',
                'command' => 'touch '.time().'.txt',
            ],
        ],
        'else' => [
            [
                'type' => 'exec',
                'command' => 'touch not_find.txt',
            ],
        ],
    ],
];

//todo делаю if for exec
function generateSession($scenario, \Yaroslam\SSH2\Session\ChainSession $session)
{
    foreach ($scenario as $s) {
        if ($s['type'] == 'exec') {
            $session->exec($s['command']);
        } elseif ($s['type'] == 'if') {
            $session->if($s['command'], $s['condition']);
            $session->then();
            $session = generateSession($s['then'], $session);
            $session->endThen();

            $session->else();
            $session = generateSession($s['else'], $session);
            $session->endElse();

            $session->endIf();
        } elseif ($s['type'] == 'for') {
            $session->for($s['start'], $s['stop'], $s['step']);
            $session = generateSession($s['body'], $session);
            $session->endFor();
        }

    }

    return $session;
}
var_dump(json_encode($a));
exit(1);
$s = new \Yaroslam\SSH2\Session\ChainSession(new UserPasswordConnection(), ['port' => 22, 'host' => '194.87.110.114',
    'properties' => ['user' => 'root', 'password' => '3w3uxhXmmh']]);
$s->initChain();
$s = generateSession($a, $s);
$s->apply();
